﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YArchitech.Plumbing
{
	internal class GroupPumpSelection : PumpGroupSelConditionInfo
	{
		public virtual bool AutoSelPump(List<HYPumpData> arrpump)
		{
			this.m_vecGroupPumpData.Clear();
			List<HYPumpData> arrSelPumps = new List<HYPumpData>();
			base.CheckFirst(arrpump, ref arrSelPumps);
			HYPumpRange hypumpRange = new HYPumpRange();
			base.GetQRange(out hypumpRange.m_dMinQ, out hypumpRange.m_dMaxQ);
			base.GetHRange(out hypumpRange.m_dMinH, out hypumpRange.m_dMaxH);
			base.GetERange(out hypumpRange.m_dMinE, out hypumpRange.m_dMaxE);
			if (this.m_bUserDefineNumber)
			{
				return this.SelPumpsUserDefine(hypumpRange, arrSelPumps);
			}
			return this.SelPumpsAuto(hypumpRange, arrSelPumps);
		}

		public bool SelPumpsAuto(HYPumpRange pumpRanges, List<HYPumpData> arrSelPumps)
		{
			int num = 1;
			for (int i = 2; i <= this.m_nMaxCounts; i++)
			{
				if (this.m_bIsParrel)
				{
					pumpRanges.m_dMinQ /= (double)i;
					pumpRanges.m_dMaxQ /= (double)i;
				}
				else
				{
					pumpRanges.m_dMinH /= (double)i;
					pumpRanges.m_dMaxH /= (double)i;
				}
				for (int j = 0; j < arrSelPumps.Count<HYPumpData>(); j++)
				{
					HYPumpData hypumpData = arrSelPumps[j];
					if (hypumpData.IsIn(pumpRanges))
					{
						hypumpData.m_leftPt.first = pumpRanges.m_dMinQ;
						hypumpData.m_leftPt.second = pumpRanges.m_dMinH;
						hypumpData.m_rightPt.first = pumpRanges.m_dMaxH;
						hypumpData.m_rightPt.second = pumpRanges.m_dMaxH;
						if (base.CheckDrawAbility(hypumpData))
						{
							HYGroupPumpData hygroupPumpData = new HYGroupPumpData();
							for (int k = 0; k < i; k++)
							{
								hygroupPumpData.m_arrData.Add(hypumpData);
							}
							string strGroupName = string.Format("自动选型方案{0}", num++);
							hygroupPumpData.m_strGroupName = strGroupName;
							hygroupPumpData.m_bIsParallel = this.m_bIsParrel;
							this.m_vecGroupPumpData.Add(hygroupPumpData);
						}
					}
				}
			}
			return true;
		}

		public bool SelPumpsUserDefine(HYPumpRange pumpRanges, List<HYPumpData> arrSelPumps)
		{
			int num = 1;
			if (this.m_bIsParrel)
			{
				pumpRanges.m_dMinQ /= (double)this.m_nUserDefineNumber;
				pumpRanges.m_dMaxQ /= (double)this.m_nUserDefineNumber;
			}
			else
			{
				pumpRanges.m_dMinH /= (double)this.m_nUserDefineNumber;
				pumpRanges.m_dMaxH /= (double)this.m_nUserDefineNumber;
			}
			for (int i = 0; i < arrSelPumps.Count<HYPumpData>(); i++)
			{
				HYPumpData hypumpData = arrSelPumps[i];
				if (hypumpData.IsIn(pumpRanges))
				{
					hypumpData.m_leftPt.first = pumpRanges.m_dMinQ;
					hypumpData.m_leftPt.second = pumpRanges.m_dMinH;
					hypumpData.m_rightPt.first = pumpRanges.m_dMaxQ;
					hypumpData.m_rightPt.second = pumpRanges.m_dMaxH;
					if (base.CheckDrawAbility(hypumpData))
					{
						HYGroupPumpData hygroupPumpData = new HYGroupPumpData();
						for (int j = 0; j < this.m_nUserDefineNumber; j++)
						{
							hygroupPumpData.m_arrData.Add(hypumpData);
						}
						string strGroupName = string.Format("自动选型方案{0}", num++);
						hygroupPumpData.m_strGroupName = strGroupName;
						hygroupPumpData.m_bIsParallel = this.m_bIsParrel;
						this.m_vecGroupPumpData.Add(hygroupPumpData);
					}
				}
			}
			return true;
		}

		public List<HYGroupPumpData> m_vecGroupPumpData = new List<HYGroupPumpData>();
	}
}
